<Query Kind="Program" />

void Main()
{
	Subject subject = new ConcreteSubject();
	Observer observer = new ConcreteObserver();
	subject.Attach(observer);
	subject.Notify();
}

abstract class Subject{
	protected List<Observer> observers = new List<Observer>();
	public abstract void Attach(Observer observer);
	public abstract void Detach(Observer observer);
	public abstract void Notify();
}

class ConcreteSubject : Subject
{
	public override void Attach(Observer observer)
	{
		observers.Add(observer);
	}

	public override void Detach(Observer observer)
	{
		observers.Remove(observer);
	}

	public override void Notify()
	{
		foreach (object obs in observers)
		{
			((Observer)obs).Update();
		}
	}
}

abstract class Observer{
	public abstract void Update();
}

class ConcreteObserver : Observer{
	public override void Update(){
		Console.WriteLine("调用了Update");
	}
}